<?php

/**
 * This is the model class for table "mst_tamu".
 *
 * The followings are the available columns in table 'mst_tamu':
 * @property string $id_tamu
 * @property string $nama
 * @property string $alamat
 * @property string $no_hp
 * @property string $foto
 * @property string $id_instansi
 *
 * The followings are the available model relations:
 * @property Instansi $idInstansi
 */
class Tamu extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Tamu the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'mst_tamu';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('nama, no_hp, foto,  id_instansi', 'required'),
			array('nama, no_hp', 'length', 'max'=>45),
			array('alamat, foto', 'length', 'max'=>50),
			array('id_instansi', 'length', 'max'=>20),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_tamu, nama, alamat, no_hp, foto,  id_instansi', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'Instansi' => array(self::BELONGS_TO, 'Instansi', 'id_instansi'),
			'Identitas' => array(self::HAS_MANY, 'Identitas', 'id_identitas'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_tamu' => 'Id Tamu',
			'nama' => 'Nama Tamu',
			'alamat' => 'Alamat',
			'no_hp' => 'No HP',
			'id_instansi' => 'Id Instansi',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_tamu',$this->id_tamu,true);
		$criteria->compare('nama',$this->nama,true);
		$criteria->compare('alamat',$this->alamat,true);
		$criteria->compare('no_hp',$this->no_hp,true);
		$criteria->compare('foto',$this->foto,true);
		$criteria->compare('id_instansi',$this->id_instansi,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}